package com.ruicar.afs.cloud.batch.frame;

import java.io.*;
import java.sql.*;

public interface BatchRunner extends Runnable{
    void saveBreakPoint(String breakPoint);
    void process(String param);
    String loadBreakPoint();
    default void clean(Connection conn){
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                
            }
        }
    }
    default void rollBack(Connection conn){
        if(conn!=null){
            try {
                conn.rollback();
            } catch (Throwable e) {

            }
        }
    }

    default void clean(PreparedStatement pstmt){
        if(pstmt!=null){
            try {
                pstmt.close();
            } catch (SQLException e) {
                
            }
        }
    }

    default void clean(Statement stmt){
        if(stmt!=null){
            try {
                stmt.close();
            } catch (SQLException e) {
                
            }
        }
    }

    default void clean(ResultSet rs){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                
            }
        }
    }

    default void clean(InputStream ips){
        if(ips!=null){
            try {
                ips.close();
            } catch (Exception e) {
                
            }
        }
    }
    default void clean(OutputStream ops){
        if(ops!=null){
            try {
                ops.close();
            } catch (Exception e) {
                
            }
        }
    }

    default void clean(Reader ops){
        if(ops!=null){
            try {
                ops.close();
            } catch (Exception e) {
                
            }
        }
    }

    /**
     * @param bos
     * return void
     * @Description
     */
    default void cleanUp(ByteArrayOutputStream bos) {
        if(bos!=null){
            try {
                bos.close();
            } catch (Exception e) {
                
            }
        }

    }

    /**
     * @param oos
     * return void
     * @Description
     */
    default void cleanUp(ObjectOutputStream oos) {
        if(oos!=null){
            try {
                oos.close();
            } catch (Exception e) {
                
            }
        }
    }

    /**
     * @param ois
     * return void
     * @Description
     */
    default void cleanUp(ObjectInputStream ois) {
        if(ois!=null){
            try {
                ois.close();
            } catch (Exception e) {
                
            }
        }
    }

    /**
     * @param bais
     * return void
     * @Description
     */
    default void cleanUp(ByteArrayInputStream bais) {
        if(bais!=null){
            try {
                bais.close();
            } catch (Exception e) {
                
            }
        }

    }

    /**
     * @param stream
     * return void
     * @Description
     */
    default void cleanUp(FileInputStream stream) {
        if(stream!=null){
            try {
                stream.close();
            } catch (Exception e) {
                
            }
        }
    }

    default void clean(Writer out) {
        if(out!=null){
            try {
                out.close();
            } catch (Exception e) {
                
            }
        }
    }
}
